<?php


namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;

class Orders extends Model
{

    use Common, SoftDeletes;

    protected $table = 'orders';

    protected $hidden = ['deleted_at'];

    protected $casts = [
        'receive_time'   => 'datetime:Y-m-d H:i:s',
        'start_time'   => 'datetime:Y-m-d H:i:s',
        'cancel_time'   => 'datetime:Y-m-d H:i:s',
        'arrive_time'   => 'datetime:Y-m-d H:i:s',
        'comment_time'   => 'datetime:Y-m-d H:i:s',
        'summary_time'   => 'datetime:Y-m-d H:i:s',
    ];

    /**
     * 公司
     * @return BelongsTo
     * @Author 姿势就是力量
     */
    public function corporation()
    {
        return $this->belongsTo(Company::class, 'company_id', 'id');
    }


    /**
     * 司机
     * @return BelongsTo
     * @Author 姿势就是力量
     */
    public function driver()
    {
        return $this->belongsTo(Drivers::class, 'driver_id', 'id');
    }


    /**
     * 乘客
     * @return BelongsTo
     * @Author 姿势就是力量
     */
    public function passenger()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }


    /**
     * 业务类型
     * @return BelongsTo
     * @Author 姿势就是力量
     */
    public function service_type()
    {
        return $this->belongsTo(ServiceType::class, 'service_type_id', 'id');
    }


    /**
     * 车辆信息
     * @return BelongsTo
     * @Author 姿势就是力量
     */
    public function car()
    {
        return $this->belongsTo(Car::class, 'car_id', 'id');
    }


    /**
     * 订单路程
     * @return HasOne
     * @Author 姿势就是力量
     */
    public function distance()
    {
        return $this->hasOne(OrderDistance::class, 'order_id', 'id');
    }

    /**
     * 订单资金流水
     * @return HasMany
     * @Author 姿势就是力量
     */
    public function flow()
    {
        return $this->hasMany(OrderFlow::class, 'order_id', 'id');
    }


    //修改后的
    /**
     * 订单资金流水
     * @return belongsTo
     * @Author 姿势就是力量
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }
}
